package com.xinchao.service;

import com.xinchao.exception.ServiceException;
import com.xinchao.model.Advertisement;
import com.xinchao.model.User;
import com.xinchao.model.dto.AdvertisementListDTO;
import com.xinchao.model.page.PageInfo;
import com.xinchao.model.sys.JsonResponse;

import java.util.List;

/**
 * @author dxy
 * @date 2018/9/18 18:28
 */
public interface AdvertisementService {
	/**
	 * 保存广告
	 *
	 * @param advertisement Advertisement
	 * @param loginUser     User
	 * @param remoteIP      远程ip
	 * @throws ServiceException
	 */
	void saveAdvertisement(Advertisement advertisement, User loginUser, String remoteIP) throws ServiceException;


	/**
	 * 保存广告并刷新缓存
	 *
	 * @param advertisement Advertisement
	 * @param loginUser     User
	 * @param remoteIP      远程ip
	 * @throws ServiceException
	 */
	void saveAdvertisementFlushCache(Advertisement advertisement, User loginUser, String remoteIP) throws ServiceException;
	/**
	 * 修改广告
	 *
	 * @param advertisement Advertisement
	 * @param loginUser     User
	 * @param remoteIP      远程ip
	 * @throws ServiceException
	 */
	void updateAdvertisementById(Advertisement advertisement, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 修改广告并刷新缓存
	 *
	 * @param advertisement Advertisement
	 * @param loginUser     User
	 * @param remoteIP      远程ip
	 * @throws ServiceException
	 */
	void updateAdvertisementFlushCache(Advertisement advertisement, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 通过ID删除广告
	 *
	 * @param advertisementId 广告ID
	 * @param loginUser       User
	 * @param remoteIP        远程ip
	 * @throws ServiceException
	 */
	void deleteAdvertisementById(Long advertisementId, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 通过ID删除广告并刷新缓存
	 *
	 * @param advertisementId 广告ID
	 * @param loginUser       User
	 * @param remoteIP        远程ip
	 * @throws ServiceException
	 */
	void deleteAdvertisementFlushCache(Long advertisementId, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 获取广告列表
	 *
	 * @param advertiserName      广告主名称
	 * @param advertisementName   广告名称
	 * @param advertisementStatus 广告状态
	 * @param sex                 性别
	 * @param age                 年龄
	 * @param pageNum             当前页
	 * @param pageSize            每页条数
	 * @return PageInfo<AdvertisementListDTO>
	 */
	PageInfo<AdvertisementListDTO> listAdvertisement(String advertiserName, String advertisementName, Integer advertisementStatus,
	                                                 Integer sex, String age, Integer pageNum, Integer pageSize);

	/**
	 * 通过广告主ID获取广告条数
	 *
	 * @param advertiserId 广告主ID
	 * @return Long
	 */
	Long countAdvertisementByAdvertiserId(Long advertiserId) throws ServiceException;

	/**
	 * 通过广告名称获取广告
	 * @param advertisementName 广告名称
	 * @return Advertisement
	 */
	Advertisement getAdvertisementByAdvertisementName(String advertisementName) throws ServiceException;

	/**
	 * 验证广告
	 * @param advertisement Advertisement
	 * @return JsonResponse
	 */
	JsonResponse validateAdvertisement(Advertisement advertisement);

	/**
	 * 更新广告状态
	 *
	 * @param advertisementId     广告ID
	 * @param advertisementName   广告名称
	 * @param advertisementStatus 广告状态
	 * @param loginUser           User
	 * @param remoteIP            远程ip
	 */
	void updateAdvertisementStatusById(Long advertisementId, String advertisementName, Integer advertisementStatus, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 更新广告状态并添加至缓存或从缓存中移除
	 *
	 * @param advertisementId     广告ID
	 * @param advertisementName   广告名称
	 * @param advertisementStatus 广告状态
	 * @param loginUser           User
	 * @param remoteIP            远程ip
	 */
	void updateAdvertisementStatusFlushCache(Long advertisementId, String advertisementName, Integer advertisementStatus, User loginUser, String remoteIP) throws ServiceException;

	/**
	 * 通过ID获取广告
	 * @param advertisementId 广告ID
	 * @return Advertisement
	 */
	Advertisement getAdvertisementById(Long advertisementId);

	/**
	 * 获取所有广告名称
	 * @return List<String>
	 */
	List<String> listAllAdvertisementName();

	/**
	 * 获取广告总数
	 * @return Long
	 */
	Long countAdvertisement();

}
